import os

from gxl_ai_utils.utils import utils_file

# input_data_dir = "/home/work_nfs14/xlgeng/asr_data_raw/test_data_raw/Leaderboard/datasets"
input_dir = "/home/work_nfs8/ixlgeng/data/scp_test"
dataset_list = os.listdir(input_dir)
# for dataset_name in dataset_list:
#     """"""
#     if dataset_name.startswith("SPEECHIO_ASR_ZH000"):
#         idx = int(dataset_name[-2:])
#         output_dataset_name = f"speechio_{idx}"
#         if idx < 5:
#             continue
#         utils_file.logging_print(f"processing {dataset_name}")
#         output_dir_temp = os.path.join(output_dir, output_dataset_name)
#         input_dir_temp = os.path.join(input_data_dir, dataset_name)
#         input_wav_path = os.path.join(input_dir_temp, "wav.scp")
#         wav_dict = utils_file.load_dict_from_scp(input_wav_path)
#         new_wav_dict = {}
#         for key,wav_path in tqdm(wav_dict.items(), total=len(wav_dict)):
#             output_wav_path = os.path.join(output_dir_temp, 'wav', f'{key}.wav')
#             utils_file.copy_file(wav_path, output_wav_path, use_shell=True)
#             new_wav_dict[key] = output_wav_path
#         output_wav_path = os.path.join(output_dir_temp, "wav.scp")
#         utils_file.write_dict_to_scp(new_wav_dict, output_wav_path)
#         input_txt_path = os.path.join(input_dir_temp, "text")
#         output_txt_path = os.path.join(output_dir_temp, "text")
#         txt_dict = utils_file.copy_file(input_txt_path, output_txt_path, use_shell=True)


for dataset_name in dataset_list:
    temp_data_dir = os.path.join(input_dir, dataset_name)
    data_list_path = os.path.join(temp_data_dir, "data.list")
    wav_scp_path = os.path.join(temp_data_dir, "wav.scp")
    text_scp_path = os.path.join(temp_data_dir, "text")
    if (not os.path.exists(data_list_path)) and os.path.exists(wav_scp_path) and os.path.exists(text_scp_path):
        utils_file.logging_print(f"processing {dataset_name}")
        utils_file.do_convert_wav_text_scp_to_jsonl(wav_scp_path, text_scp_path, data_list_path)
